import nodemailer from "nodemailer";
import { config } from "../config/index";
const transporter = nodemailer.createTransport({
  // host: 'smtp.163.com',
  service: config.service, //邮箱类型 例如service:'163'
  // secure: true, //是否使用安全连接，对https协议的
  port: config.qqport, //qq邮件服务所占用的端口
  auth: {
    user: config.user, //开启SMTP的邮箱，发件人
    pass: config.pass, // qq授权码
  },
});
const send = async (to: any, subject: any, text: any, a: any = transporter) => {
  let options = {
    from: "514头条 <2954020052@qq.com>", //发送方
    to: to, //"xxx@qq.com",//接收方
    subject: subject, //'111111111111',//邮件主题
    html: `<h1>您的验证码是${text}</h1>`, //'<h1>您好</h1>',//html模板
  };
  return new Promise((resolve, reject) => {
    a.sendMail(options, (err: any, info: any) => {
      if (err) {
        reject(err);
      } else {
        resolve(info);
      }
    });
  })
    .catch((e) => {
      throw e;
    })
    .finally(() => {
      a.close();
    });
};
export { send };
